/* *****************************************************************************
*
*	danizone.ch
*
*	Developer:		mda010
*	Creation date:	May 6, 2012 3:55:42 PM
*	
*	Project name:	HomegrownCuisine
*	File name:		HomeController.java
*
*	Copyrights (C) 2012 @danizone.ch
*
*   This program is free software; you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation; either version 2 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*	GNU General Public License for more details.
*
*	Change history:	[developer]; [date];[reason for change]
*
*					mda010; May 6, 2012; created
*
***************************************************************************** */
package ch.zhaw.hgc.controllers;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import ch.zhaw.hgc.services.IRecipeService;

/**
 * Implementation note goes here!
 */
@Controller
@RequestMapping("/")
public class HomeController{
	
	private static final Logger logger = Logger.getLogger(HomeController.class);
	
	@Autowired
	private IRecipeService recipeService;
	
	@RequestMapping(method=RequestMethod.GET)
	public ModelAndView get(HttpServletRequest request){
		String sortableField = request.getParameter("sortableField");
		String direction = request.getParameter("direction");
 		ModelAndView mav = new ModelAndView("home");
		mav.addObject("recipes", recipeService.findAll(sortableField, direction));			
		logger.info("Passed get() method in controller...");
		
		return mav;
	}
	
}